package com.example.controller;

import com.example.common.Result;
import com.example.entity.Checkpoint;
import com.example.entity.CommonQuestion;
import com.example.service.CommonQuestionService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 常见问题前端接口
 */
@ApiIgnore
@RestController
@RequestMapping("/commonQuestion")
public class CommonQuestionController {

    @Resource
    private CommonQuestionService commonQuestionService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody CommonQuestion commonQuestion) {
        commonQuestionService.add(commonQuestion);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        commonQuestionService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        commonQuestionService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody CommonQuestion commonQuestion) {
        commonQuestionService.updateById(commonQuestion);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        CommonQuestion commonQuestion = commonQuestionService.selectById(id);
        return Result.success(commonQuestion);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(CommonQuestion commonQuestion ) {
        List<CommonQuestion> commonQuestionList = commonQuestionService.selectAll(commonQuestion);
        return Result.success(commonQuestionList);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(CommonQuestion commonQuestion,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<CommonQuestion> pageInfo = commonQuestionService.selectPage(commonQuestion, pageNum, pageSize);
        return Result.success(pageInfo);
    }

}
